package com.hfy.shop.controller;

import com.hfy.model.dto.order.CreateOrderDto;
import com.hfy.shop.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

/**
 * @ author 韩
 * time: 2024/9/10 16:22
 */

@RestController
@RequestMapping("/order")
@Tag(name = "订单控制器" ,description = "在支付控制器和商品控制器中处于中间状态")
public class OrderController {
    @Autowired
    private OrderService orderService;


    @PostMapping("/create")
    @Operation(summary = "创建订单",description = "根据账号，和商品创建订单")
    @Parameters({@Parameter(name = "goodId",description = "商品ID"),
            @Parameter(name = "account",description = "用户账号"),
    })
    public Result creatOrder(@RequestBody CreateOrderDto dto) {
        return orderService.creatOrder(dto);
    }

    @GetMapping("/info/{id}")
    @Operation(summary = "获取订单详情",description = "根据订单id，获取订单详情")
    @Parameters({
            @Parameter(name = "status",description = "订单状态"),
    })
    public Result getOrderInfo(@PathVariable("id") String id) {
        return orderService.getOrderInfo(id);
    }
    @GetMapping("/list/{account}/{status}")
    @Operation(summary = "获取订单列表",description = "根据订单状态，获取相应状态的订单列表")
    @Parameters({
            @Parameter(name = "status",description = "订单状态"),
    })
    public Result getOrderListByStatus(@PathVariable("status") String status, @PathVariable("account") Long account) {
        return orderService.getOrderListByStatus(status, account);
    }




}
